home *** CD-ROM | disk | FTP | other *** search
- //--------------------------------------------------------------------------
- //
- // MyMediaComponent.
- // by John Wang
- //
- // Description: Sample Derived Media Component.
- //
- // Version: 1.0 02/25/93 Based on MyComponent shell.
- //
- //--------------------------------------------------------------------------
-
- //
- // #includes
- //
-
- #include <Components.h>
- #include <MediaHandlers.h>
- #include "MyMediaComponent.h"
- #include "MyMediaComponentRoutines.h"
- #include "MyMemory.h"
- #include "MyUtilities.h"
-
- //--------------------------------------------------------------------------
-
- // Component entry point.
-
- pascal ComponentResult main(ComponentParameters *params, PrivateGlobals **storage)
- {
- switch (params->what) {
- case kComponentOpenSelect:
- return CallComponentFunction(params, (ComponentFunction) MyOpen);
- case kComponentCloseSelect:
- return CallComponentFunctionWithStorage((char **) storage, params,
- (ComponentFunction) MyClose);
- case kComponentCanDoSelect:
- return CallComponentFunction(params, (ComponentFunction) MyCanDo);
- case kComponentVersionSelect:
- return CallComponentFunction(params, (ComponentFunction) MyVersion);
- case kComponentRegisterSelect:
- return CallComponentFunctionWithStorage((char **) storage, params,
- (ComponentFunction) MyRegister);
- case kMediaInitializeSelect:
- return CallComponentFunctionWithStorage((char **) storage, params,
- (ComponentFunction) MyMediaInitialize);
- case kMediaIdleSelect:
- return CallComponentFunctionWithStorage((char **) storage, params,
- (ComponentFunction) MyMediaIdle);
- case kMediaSetActiveSelect:
- return CallComponentFunctionWithStorage((char **) storage, params,
- (ComponentFunction) MyMediaSetActive);
- case kMediaSetRateSelect:
- return CallComponentFunctionWithStorage((char **) storage, params,
- (ComponentFunction) MyMediaSetRate);
- case kMediaTrackEditedSelect:
- return CallComponentFunctionWithStorage((char **) storage, params,
- (ComponentFunction) MyMediaTrackEdited);
- case kMediaSetGWorldSelect:
- return CallComponentFunctionWithStorage((char **) storage, params,
- (ComponentFunction) MyMediaSetGWorld);
- case kMediaSetDimensionsSelect:
- return CallComponentFunctionWithStorage((char **) storage, params,
- (ComponentFunction) MyMediaSetDimensions);
- case kMediaSetMatrixSelect:
- return CallComponentFunctionWithStorage((char **) storage, params,
- (ComponentFunction) MyMediaSetMatrix);
- case kMediaSampleDescriptionChangedSelect:
- return CallComponentFunctionWithStorage((char **) storage, params,
- (ComponentFunction) MyMediaSampleDescriptionChanged);
-
- default:
- if ((**storage).delegate) {
- // If base media handler is targeted, then delegate all unimplemented
- // calls to the base media handler.
- long ret;
-
- ret = DelegateComponentCall(params, (**storage).delegate);
- if (DEBUGME && (params->what > 0x500) && (params->what < 0x5ff)) {
- // Show all delegation to media handler
- Str255 myStr;
-
- BlockMove("\PDelegating selector: 0x Return value: ", myStr, 66);
- HexToString(params->what, (char *) &myStr[24]);
- LongToString(ret, (char *) &myStr[44]);
- DebugStr(myStr);
- }
- return(ret);
- } else {
- // If base media handler has not been targeted, then return paramErr.
- return(paramErr);
- }
- }
- }
-
- //--------------------------------------------------------------------------
-
- // Required component calls.
-
- pascal ComponentResult MyOpen(ComponentInstance self)
- {
- PrivateGlobals **storage;
- ComponentInstance myComp;
-
- if (DEBUGME == 1)
- DebugStr("\PIn MyOpen()");
-
- // Open base media handler component and target it.
- if ((myComp = OpenDefaultComponent(MediaHandlerType, BaseMediaType)) == nil) {
- return(componentNotCaptured);
- }
- ComponentSetTarget(myComp, self);
-
- // Create private globals and initialize private variables.
- if ((storage=(PrivateGlobals **)MyNewHandleClear(sizeof(PrivateGlobals))) == nil ) {
- return(memFullErr);
- }
- SetComponentInstanceStorage(self, (Handle) storage);
- (**storage).delegate = myComp;
- (**storage).self = self;
-
- // This component does not use shared globals. Therefore, we don't use the refcon.
- return(noErr);
- }
-
- pascal ComponentResult MyClose(PrivateGlobals **storage, ComponentInstance self)
- {
- if (DEBUGME == 1)
- DebugStr("\PIn MyClose()");
-
- // If storage has been allocated, then close base media handler component instance.
- if (storage) {
- if ((**storage).delegate) {
- CloseComponent((**storage).delegate);
- (**storage).delegate = nil;
- }
- }
-
- // Dispose of private variables created by the open routine. Since MyClose may called
- // even though MyOpen failed, we want to make sure that the handle is allocated before
- // disposing of it. MyDiposeHandle does just that. It doesn't dispose of the handle if
- // it is nil. If it is not nil, it disposes of it, then sets the handle to nil.
- MyDisposeHandle((Handle *) &storage);
-
- return(noErr);
- }
-
- pascal ComponentResult MyCanDo(short selector)
- {
- if (DEBUGME == 1)
- DebugStr("\PIn MyCanDo()");
-
- switch (selector) {
- // Required component calls.
- case kComponentOpenSelect:
- case kComponentCloseSelect:
- case kComponentCanDoSelect:
- case kComponentVersionSelect:
- case kComponentRegisterSelect:
-
- // MyComponent specific calls.
- case kMediaInitializeSelect:
- case kMediaIdleSelect:
- case kMediaSetActiveSelect:
- case kMediaSetRateSelect:
- case kMediaTrackEditedSelect:
- case kMediaSetGWorldSelect:
- case kMediaSetDimensionsSelect:
- case kMediaSetMatrixSelect:
- case kMediaSampleDescriptionChangedSelect:
- return(true);
-
- // Otherwise, return FALSE.
- default:
- if (DEBUGME) {
- Str255 myStr;
-
- BlockMove("\PCan't do: 0x ", myStr, 25);
- HexToString(selector, (char *) &myStr[13]);
- DebugStr(myStr);
- }
- return (false);
- }
- }
-
- pascal ComponentResult MyVersion()
- {
- if (DEBUGME == 1)
- DebugStr("\PIn MyVersion()");
-
- return ((kMyComponentSpec<<16) || (kMyComponentVersion));
- }
-
- pascal ComponentResult MyRegister(PrivateGlobals **storage)
- {
- if (DEBUGME == 1)
- DebugStr("\PIn MyRegister()");
-
- // We will actually never get this far because the MyOpen routine would have returned an
- // error which would have already notified the Component Manager not to register us.
- // We still put the code here since the Component Manager expects us to implement this
- // routine since we set the wantsRegisterMessage flag. If we didn't set the flag,
- // our component would never get opened during registration and we would always get
- // registered even if the base media handler was unavailable. i.e. under QuickTime 1.0.
- if (storage)
- return (FALSE); // Globals properly set up meaning that base media handler targeted ok
- else
- return (TRUE); // Globals not properly set up meaning we don't register
- }